package com.yxhl.zoume.utils;

import android.content.Context;
import android.support.annotation.RawRes;
import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by vhawk on 11/21/16.
 */

public class HTMLUtils {
    /**
     * 获取html内容
     *
     * @param context
     * @param htmlRes
     * @return
     */
    public static Spanned getRawContent(Context context, @RawRes int htmlRes) {
        InputStream is = context.getResources().openRawResource(htmlRes);
        try {
            DataInputStream dis = new DataInputStream(is);
            byte[] buffer = new byte[is.available()];
            dis.readFully(buffer);
            dis.close();
            is.close();
            return Html.fromHtml(new String(buffer));
        } catch (IOException e) {
            e.printStackTrace();
        }

        return new SpannableString("");
    }
}
